using System;
using System.Collections;
using System.Text;
using 修为尽失.辅助.Resources;

namespace 修为尽失.辅助
{
    public static class Statics
    {
        public static string ToLogString(this Exception ex)
        {
            if (ex == null)
                return string.Empty;
            var stringBuilder1 = new StringBuilder();
            stringBuilder1.Append("  >>异常消息（Message）:").AppendLine(ex.Message);
            stringBuilder1.Append("  >>异常来源（Source）:").AppendLine(ex.Source);
            stringBuilder1.Append("  >>异常类型（ExceptionType）:").AppendLine(ex.GetType().ToString());
            stringBuilder1.Append("  >>原生异常类型（BaseExceptionType）:").AppendLine(ex.GetBaseException().GetType().ToString());
            stringBuilder1.Append("  >>出错的方法签名（TargetSite）:").Append(ex.TargetSite);
            if (ex.Data.Count > 0)
            {
                stringBuilder1.Append(Environment.NewLine);
                stringBuilder1.Append("  >>自定义数据（Data）:");
                var stringBuilder2 = new StringBuilder();
                foreach (DictionaryEntry dictionaryEntry in ex.Data)
                    stringBuilder2.Append("Key:" + dictionaryEntry.Key + "，Value:" + dictionaryEntry.Value + "; ");
                stringBuilder1.Append(stringBuilder2);
            }

            if (!string.IsNullOrEmpty(ex.StackTrace))
            {
                stringBuilder1.Append(Environment.NewLine);
                stringBuilder1.Append("  >>堆栈信息（StackTrace）:");
                stringBuilder1.Append(Environment.NewLine);
                stringBuilder1.Append(ex.StackTrace);
            }

            if (ex.InnerException != null)
            {
                stringBuilder1.Append(Environment.NewLine);
                stringBuilder1.Append(">>========================== 内部异常（InnerException）==========================");
                stringBuilder1.Append(Environment.NewLine);
                stringBuilder1.Append(ex.InnerException.ToLogString());
            }

            return stringBuilder1.ToString();
        }

        public static string ToFormattedString(this DateTime dt, string fmt = ResManager.Strings.DT)
        {
            return dt.ToString(fmt);
        }
        public static string ToFormattedString_dtfff(this DateTime dt)
        {
            return dt.ToString(ResManager.Strings.DTfff);
        }
         
    }
}